package com.fourmob.datetimepicker.date;

import com.fourmob.datetimepicker.util.ViewAnimator;

import ohos.accessibility.AccessibilityEventInfo;
import ohos.agp.components.AttrSet;
import ohos.app.Context;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class AccessibleDateAnimator extends ViewAnimator {
    private static HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x000110, "DatePickerDialog");
    private AccessibilityEventInfo eventInfo;

    /**
     * 构造方法
     * @param context
     * @param attrs
     */
    public AccessibleDateAnimator(Context context, AttrSet attrs) {
        super(context,attrs);
    }

    @Override
    public void notifyAccessibility(int eventType) {
        super.notifyAccessibility(eventType);
        HiLog.info(label, "ADA_notifyAccessiblity01");
        eventInfo = new AccessibilityEventInfo(eventType);
        dispatchPopulateAccessibilityEvent(eventInfo);
        HiLog.info(label, "ADA_notifyAccessiblity01");
    }

    /**
     *
     * 可改更数据类型
     *
     * @param event
     * @return 可访问事件的类型是否为TYPE_VIEW_TEXT_SELECTION_CHANGED_EVENT
     */
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEventInfo event) {
        if (event.getAccessibilityEventType() == AccessibilityEventInfo.TYPE_VIEW_TEXT_SELECTION_CHANGED_EVENT) {
            HiLog.info(label, "ADA_dispatchPopulateAccessibilityEvent");
            event.getContentList().clear();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL);
            String dateString = dateTimeFormatter.toString();
            event.getContentList().add(dateString);
            return true;
        }
        return false;
    }
}
